package com.zhitong.ztblog.services.servicesImp;

import com.zhitong.ztblog.entity.Comment;
import com.zhitong.ztblog.entity.PageInfo;
import com.zhitong.ztblog.mappers.CommentMapper;
import com.zhitong.ztblog.services.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class CommentService implements ICommentService {
    @Autowired
    private CommentMapper mapper;

    @Override
    public Comment[] findByBid(int bid) {
        Comment[] comments = mapper.findByBid(bid);
        return comments;
    }

    @Override
    public void insertComment(Comment comment){
        comment.setCreateTime(new Date());
        mapper.insertComment(comment);
    }

    @Override
    public Comment[] findCommentByPage(PageInfo pageInfo) {
        Comment[] commentByPage = mapper.findCommentByPage((pageInfo.getCurrentPage() - 1) * pageInfo.getPageSize(), pageInfo.getPageSize());
        return commentByPage;
    }

    @Override
    public int findCount() {
        return mapper.findCount();
    }

    @Override
    public void delCommentById(int id) {
        mapper.delCommentById(id);
    }
}
